package org.framework.edge.builder.application.impl;

import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.framework.edge.builder.application.DockerRepositoryBackupRecordApplication;
import org.springframework.web.bind.annotation.*;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.framework.edge.builder.domain.model.docker.repository.backup.record.DockerRepositoryBackupRecord;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordRemoveCommand;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordStoryCommand;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordUpdateCommand;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordQueryListCommand;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordQueryOneCommand;
import org.framework.edge.builder.application.assembler.DockerRepositoryBackupRecordDTOAssembler;
import org.framework.edge.builder.application.dto.DockerRepositoryBackupRecordDTO;
import java.util.stream.Collectors;
import jakarta.annotation.Resource;
import org.framework.edge.builder.domain.model.docker.repository.backup.record.DockerRepositoryBackupRecordRepository;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordExcelExport;
import org.framework.edge.builder.application.command.docker.repository.backup.record.DockerRepositoryBackupRecordExcelImport;
/**
 * describe Docker仓库备份记录 
 *
 * @author Jia wei Wu
 * @date 2025/07/10 08:18 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class DockerRepositoryBackupRecordApplicationImpl implements DockerRepositoryBackupRecordApplication {

    @Resource
    DockerRepositoryBackupRecordRepository dockerRepositoryBackupRecordRepository;
    /**
     * describe 新增Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordStoryCommand 新增Docker仓库备份记录     
     * @return {@link Result<DockerRepositoryBackupRecord>} Docker仓库备份记录新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<DockerRepositoryBackupRecord> story(DockerRepositoryBackupRecordStoryCommand dockerRepositoryBackupRecordStoryCommand) {
        DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordStoryCommand);
        return dockerRepositoryBackupRecordRepository.story(dockerRepositoryBackupRecord);
    }
    /**
     * describe 批量新增Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordStoryCommandList 批量新增Docker仓库备份记录     
     * @return {@link Result<List<DockerRepositoryBackupRecord>>} Docker仓库备份记录新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<List<DockerRepositoryBackupRecord>> batchStory(List<DockerRepositoryBackupRecordStoryCommand> dockerRepositoryBackupRecordStoryCommandList) {
        List<DockerRepositoryBackupRecord> dockerRepositoryBackupRecordList = dockerRepositoryBackupRecordStoryCommandList.stream().map( DockerRepositoryBackupRecordDTOAssembler.INSTANCE::toDockerRepositoryBackupRecord).collect(Collectors.toList());
        return dockerRepositoryBackupRecordRepository.batchStory(dockerRepositoryBackupRecordList);
    }
    /**
     * describe 更新Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordUpdateCommand 更新Docker仓库备份记录     
     * @return {@link Result<DockerRepositoryBackupRecord>} Docker仓库备份记录领域对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<DockerRepositoryBackupRecord> updateOne(DockerRepositoryBackupRecordUpdateCommand dockerRepositoryBackupRecordUpdateCommand) {
        DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordUpdateCommand);
        return dockerRepositoryBackupRecordRepository.story(dockerRepositoryBackupRecord);
    }

    /**
     * describe 查询单个Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordQueryOneCommand 查询单个Docker仓库备份记录     
     * @return {@link Result<DockerRepositoryBackupRecordDTO>} Docker仓库备份记录DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<DockerRepositoryBackupRecordDTO> findOne(DockerRepositoryBackupRecordQueryOneCommand dockerRepositoryBackupRecordQueryOneCommand) {
        DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordQueryOneCommand);
        return dockerRepositoryBackupRecordRepository.findOne(dockerRepositoryBackupRecord).convert(DockerRepositoryBackupRecordDTOAssembler.INSTANCE::fromDockerRepositoryBackupRecord);
    }

    /**
     * describe 查询多个Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordQueryListCommand 查询多个Docker仓库备份记录     
     * @return {@link Result<List<DockerRepositoryBackupRecordDTO>>} Docker仓库备份记录DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<List<DockerRepositoryBackupRecordDTO>> findList(DockerRepositoryBackupRecordQueryListCommand dockerRepositoryBackupRecordQueryListCommand) {
        DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordQueryListCommand);
        return dockerRepositoryBackupRecordRepository.findList(dockerRepositoryBackupRecord)        .convert(dockerRepositoryBackupRecords -> dockerRepositoryBackupRecords.stream().map(DockerRepositoryBackupRecordDTOAssembler.INSTANCE::fromDockerRepositoryBackupRecord).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordQueryListCommand 分页查询多个Docker仓库备份记录     
     * @return {@link Result<LazyPage<DockerRepositoryBackupRecordDTO>>} 分页Docker仓库备份记录DTO对象     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<LazyPage<DockerRepositoryBackupRecordDTO>> findPage(int size,int current,DockerRepositoryBackupRecordQueryListCommand dockerRepositoryBackupRecordQueryListCommand) {
        DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordQueryListCommand);
        return dockerRepositoryBackupRecordRepository.findPage(size,current,dockerRepositoryBackupRecord)        .convert(page -> page.convert(DockerRepositoryBackupRecordDTOAssembler.INSTANCE::fromDockerRepositoryBackupRecord))            ;
    }

    /**
     * describe 删除Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordRemoveCommand 删除Docker仓库备份记录     
     * @return {@link Result<DockerRepositoryBackupRecord>} Docker仓库备份记录     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<DockerRepositoryBackupRecord> remove(DockerRepositoryBackupRecordRemoveCommand dockerRepositoryBackupRecordRemoveCommand) {
     DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordRemoveCommand);
     return dockerRepositoryBackupRecordRepository.remove(dockerRepositoryBackupRecord);
    }

    /**
     * describe 导出Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordQueryListCommand 导出Docker仓库备份记录     
     * @return {@link List<DockerRepositoryBackupRecordExcelExport>} Docker仓库备份记录     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public List<DockerRepositoryBackupRecordExcelExport> exportExcel(DockerRepositoryBackupRecordQueryListCommand dockerRepositoryBackupRecordQueryListCommand) {
     DockerRepositoryBackupRecord dockerRepositoryBackupRecord = DockerRepositoryBackupRecordDTOAssembler.INSTANCE.toDockerRepositoryBackupRecord(dockerRepositoryBackupRecordQueryListCommand);
        return dockerRepositoryBackupRecordRepository.findList(dockerRepositoryBackupRecord)        .applyOther(dockerRepositoryBackupRecords -> dockerRepositoryBackupRecords.stream().map(DockerRepositoryBackupRecordDTOAssembler.INSTANCE::fromDockerRepositoryBackupRecordToExcelExport).collect(Collectors.toList())) ;
    }

    /**
     * describe 导入Docker仓库备份记录
     *
     * @param dockerRepositoryBackupRecordExcelImportList 导入Docker仓库备份记录     
     * @return {@link Result<DockerRepositoryBackupRecordExcelImport>} Docker仓库备份记录     
     
     * @author Jia wei Wu
     * @date 2025/07/10 08:18 晚上
     **/

    @Override
    public Result<List<DockerRepositoryBackupRecordExcelImport>> importExcel(List<DockerRepositoryBackupRecordExcelImport> dockerRepositoryBackupRecordExcelImportList) {
        List<DockerRepositoryBackupRecord> dockerRepositoryBackupRecordList = dockerRepositoryBackupRecordExcelImportList.stream().map( DockerRepositoryBackupRecordDTOAssembler.INSTANCE::toDockerRepositoryBackupRecord).collect(Collectors.toList());
        dockerRepositoryBackupRecordRepository.batchStory(dockerRepositoryBackupRecordList);
        return ResultFactory.successOf(dockerRepositoryBackupRecordExcelImportList);
    }
}